package com.ruoyi.manage.organization.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.utils.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.ListUtil;
import com.ruoyi.manage.organization.domain.OcBusinessFinancingOrder;
import com.ruoyi.manage.organization.domain.OcOrderRepayment;
import com.ruoyi.manage.organization.mapper.OcOrderRepaymentMapper;
import com.ruoyi.manage.organization.service.IOcBusinessFinancingOrderService;
import com.ruoyi.manage.organization.service.IOcOrderRepaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 订单还款记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-20
 */
@Service
public class OcOrderRepaymentServiceImpl extends ServiceImpl<OcOrderRepaymentMapper, OcOrderRepayment> implements IOcOrderRepaymentService {

    @Autowired
    IOcBusinessFinancingOrderService iOcBusinessFinancingOrderService;

    @Override
    public OcOrderRepayment queryGetById(Long id) {
        OcOrderRepayment ocOrderRepayment = this.getById(id);
        return ocOrderRepayment;
    }

    /**
     * 新增订单还款记录
     *
     * @param ocOrderRepayment 订单还款记录
     * @return 结果
     */
    @Override
    public boolean addOcOrderRepayment(OcOrderRepayment ocOrderRepayment) {
        String paymentState = "0";
        iOcBusinessFinancingOrderService.update(new UpdateWrapper<OcBusinessFinancingOrder>()
                .set("payment_state", paymentState)
                .eq("order_no", ocOrderRepayment.getOrderNo()));

        boolean save = this.save(ocOrderRepayment);
        return save;
    }

    /**
     * 修改订单还款记录
     *
     * @param ocOrderRepayment 订单还款记录
     * @return 结果
     */
    @Override
    public boolean updateOcOrderRepayment(OcOrderRepayment ocOrderRepayment) {
        return this.updateById(ocOrderRepayment);
    }

    /**
     * 批量删除订单还款记录
     *
     * @param ids 需要删除的订单还款记录主键
     * @return 结果
     */
    @Override
    public boolean deleteOcOrderRepaymentByIds(Long[] ids) {
        return this.removeByIds(ListUtil.toList(ids));
    }

}
